package com.fenghen.system.controller;

import com.fenghen.common.annotation.Log;
import com.fenghen.common.core.controller.BaseController;
import com.fenghen.common.core.domain.AjaxResult;
import com.fenghen.common.core.page.TableDataInfo;
import com.fenghen.common.enums.BusinessType;
import com.fenghen.common.utils.poi.ExcelUtil;
import com.fenghen.system.domain.ResourcePlanning;
import com.fenghen.system.service.IResourcePlanningService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资源规划管理Controller
 * 
 * @author fenghen
 * @date 2024-11-03
 */
@Controller
@RequestMapping("/system/planning")
public class ResourcePlanningController extends BaseController
{
    private String prefix = "system/planning";

    @Autowired
    private IResourcePlanningService resourcePlanningService;

    @RequiresPermissions("system:planning:view")
    @GetMapping()
    public String planning()
    {
        return prefix + "/planning";
    }

    /**
     * 查询资源规划管理列表
     */
    @RequiresPermissions("system:planning:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ResourcePlanning resourcePlanning)
    {
        startPage();
        List<ResourcePlanning> list = resourcePlanningService.selectResourcePlanningList(resourcePlanning);
        return getDataTable(list);
    }

    /**
     * 导出资源规划管理列表
     */
    @RequiresPermissions("system:planning:export")
    @Log(title = "资源规划管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ResourcePlanning resourcePlanning)
    {
        List<ResourcePlanning> list = resourcePlanningService.selectResourcePlanningList(resourcePlanning);
        ExcelUtil<ResourcePlanning> util = new ExcelUtil<ResourcePlanning>(ResourcePlanning.class);
        return util.exportExcel(list, "资源规划管理数据");
    }

    /**
     * 新增资源规划管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存资源规划管理
     */
    @RequiresPermissions("system:planning:add")
    @Log(title = "资源规划管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ResourcePlanning resourcePlanning)
    {
        return toAjax(resourcePlanningService.insertResourcePlanning(resourcePlanning));
    }

    /**
     * 修改资源规划管理
     */
    @RequiresPermissions("system:planning:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ResourcePlanning resourcePlanning = resourcePlanningService.selectResourcePlanningById(id);
        mmap.put("resourcePlanning", resourcePlanning);
        return prefix + "/edit";
    }

    /**
     * 修改保存资源规划管理
     */
    @RequiresPermissions("system:planning:edit")
    @Log(title = "资源规划管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ResourcePlanning resourcePlanning)
    {
        return toAjax(resourcePlanningService.updateResourcePlanning(resourcePlanning));
    }

    /**
     * 删除资源规划管理
     */
    @RequiresPermissions("system:planning:remove")
    @Log(title = "资源规划管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(resourcePlanningService.deleteResourcePlanningByIds(ids));
    }
}
